<template>
	<block v-if="isInline">
		<view v-if="(isShow&&!noAuth) || (noAuth && !isShow)" style="display: inline-block;">
			<slot></slot>
		</view>
	</block>
	<block v-else>
		<view v-if="(isShow&&!noAuth) || (noAuth && !isShow)">
			<slot></slot>
		</view>
	</block>
</template>

<script>
	export default {
		name : "auth" ,
		props:{
			url : { //请求权限地址
				type : String , 
				default : ""
			},
			noAuth:{
				type : Boolean , //是否验证无权限
				default : false
			},
			isInline : {
				type : Boolean ,
				default : true 
			}
		},
		created : function(e){
			this.check();
		},
		data() {
			return {
				isShow : false ,
				times : 200 //请求验证的次数
			};
		},
		methods:{
			check : function(){
				var url = this.url ;
				if (!this.url) {
					this.isShow = true ;
					return false ;
				}
				var index = this.url.indexOf("?");
				if(index > -1){
					url = url.substr(0,index);
				}
				var menuList = getApp().globalData.menuList ;
				if (menuList.length > 0) {
					for (var i = 0; i < menuList.length; i++) {
						var cur = menuList[i];
						if( (cur.url + ";").indexOf(url+";") > -1){
							this.isShow = true ;
							return false ;
						}
					}
					console.log("noAuth:" , url);
				}else{
					var that = this ;
					if(that.times <= 0){
						return false ;
					}
					setTimeout(function(res){
						that.times -- ;
						that.check();
					},200);
				}
			}
		}
	}
</script>

<style>

</style>
